package com.imooc.spark

import java.sql.DriverManager

/**
  * Created by zghgchao 2017/12/22 22:03
  * 通过JDBC的方式访问
  */
object SparkSQLThriftServerApp {
  def main(args: Array[String]): Unit = {
    Class.forName("org.apache.hive.jdbc.HiveDriver")

    //注意：要先启动thriftserver  ./sbin/start-thriftserver.sh --master local[2]
    val conn = DriverManager.getConnection("jdbc:hive2://172.17.66.51:10000", "hadoop", "")
    val pstmt = conn.prepareStatement("select empno,ename,sal from emp")
    val rs = pstmt.executeQuery()
    while (rs.next()) {
      println("empno:" + rs.getInt("empno") +
        ", ename:" + rs.getString("ename") +
        ", sal:" + rs.getDouble("sal"))
    }
  }
}
